<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Components - Vue Lesson 2</title>
    <script src="bower_components/vue/dist/vue.min.js"></script>
</head>
<body>

<!--自定义组件-->
<div id="example">
    <my-component></my-component>
</div>

</body>
<script>
    // 注册
    Vue.component('my-component', {
        template: '<div>A custom component!</div>'
    })
    // 创建根实例
    new Vue({
        el: '#example'
    })
</script>
<!---/END 自定义组件-->


<div id="app-7">
    <ol>
        <!-- 现在我们为每个todo-item提供待办项对象    -->
        <!-- 待办项对象是变量，即其内容可以是动态的 -->
        <todo-item v-for="item in groceryList" v-bind:todo="item"></todo-item>
    </ol>
</div>

<script type="text/javascript">
    Vue.component('todo-item', {
        props: ['todo'],
        template: '<li>{{ todo.text }}</li>'
    });

    var app7 = new Vue({
        el: '#app-7',
        data: {
            groceryList: [
                { text: '蔬菜' },
                { text: '奶酪' },
                { text: '随便其他什么人吃的东西' }
            ]
        }
    })
</script>


<!-- 组件嵌套 -->
<div id="app-8">
    <div class="article-container">
        <article-lists v-bind:articles="articles"></article-lists>
    </div>
</div>

<script type="text/javascript">

    Vue.component('article-lists', {
        props: ['articles'],
        template: '<div class="articles-content"><article-item v-for="(item,key) in articles" v-bind:todo="item" v-bind:key="key"></article-item></div>' //组件循环体需要上层父节点
    });

    Vue.component('article-item', {
        props: ['todo'],
        template: '<li>{{ todo.text }}</li>'
    });


    var app8 = new Vue({
        el: '#app-8',
        data: {
            articles: [
                { text: '蔬菜 1' },
                { text: '奶酪 1' },
                { text: '随便其他什么人吃的东西 1' }
            ]
        },
    })
</script>
<!--／END 组件嵌套 -->

</body>
</html>